﻿@model PaginatedList<WebshopHPWcore.Models.Car>

@{
    ViewData["Title"] = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<br />
<h2>Auto Beheer</h2>
<br />
<p>
    <a asp-action="Create">Nieuwe auto toevoegen</a>
</p>

<form  asp-action="Index" method="get">
    <div class="form-actions no-color">
        <input type="submit" value="Zoeken" class="btn btn-default" />
        <a class="btn btn-default" asp-action="index"
           asp-route-searchString=""
           asp-route-searchStringModel=""
           asp-route-carColor=""
           asp-route-fueltype=""
           asp-route-transmission=""
           asp-route-minPrice=""
           asp-route-maxPrice=""
           asp-route-milage=""
           asp-route-bouwjaar="">

            Verwijder Filter(s)
        </a><br /><br />
        <b>Huidig Filter(s): </b> <br />
        Merk + model: @ViewData["CurrentFilter"] @ViewData["CurrentFilterModel"]
        Bouwjaar @ViewData["ManufactureYear"]
        Kleur: @ViewData["ColorFilter"]
        Prijs: @ViewData["MinPriceFilter"] - @ViewData["MaxPriceFilter"]
        Brandstof: @ViewData["FuelTypeFilter"]
        Transmissie: @ViewData["TransmissionFilter"]
        Kilometerstand @ViewData["MilageFilter"]
        <br />
        <br />

        <b>Merken:</b>
        <select id="searchString" name="searchString" value="@ViewData["currentFilter"]">
            <option value="@ViewData["CurrentFilter"]">Alle</option>
            @foreach (var item in Model.AllItems.OrderBy(s => s.brand).Select(s => s.brand).Distinct())
            {
                <option value=@item>@item</option>
            }
        </select>
        &nbsp;&nbsp;
        @if (ViewData["currentFilter"] != null)
            {
            <b>Model:</b>
            <select id="searchStringModel" name="searchStringModel" value="@ViewData["CurrentFilterModel"] ">
                <option value="@ViewData["CurrentFilterModel"] ">Alle</option>
                @foreach (var item in Model.AllItems.OrderBy(s => s.model).Select(s => s.model).Distinct())
                {
                    <option value=@item>@item</option>
                }
            </select>
        }
        &nbsp;&nbsp;
        <b>Bouwjaar:</b>
        <input name="ManufactureYear" value="@ViewData["ManufactureYear"]" type="text" onkeypress='return event.charCode >= 48 && event.charCode <= 57'>
        &nbsp;&nbsp;
        <b>Kleur:</b>
        <select id="color" name="carColor" value="@ViewData["ColorFilter"]">
            <option value="@ViewData["ColorFilter"]">Alle</option>
            @foreach (var item in Model.AllItems.OrderBy(s => s.color).Select(s => s.color).Distinct())
            {
                <option value=@item>@item</option>
            }
        </select><br /><br />

        <b>Minimum prijs:</b>
        <input name="minPrice" value="@ViewData["MinPriceFilter"]" type="text" onkeypress='return event.charCode >= 48 && event.charCode <= 57'>
        &nbsp;
        <b>Maximum prijs:</b>
        <input name="maxPrice" value="@ViewData["MaxPriceFilter"]" type="text" onkeypress='return event.charCode >= 48 && event.charCode <= 57'>
        &nbsp;&nbsp;
        <b>Type brandstof:</b>
        <select id="fueltype" name="fuelType" value="@ViewData["FuelTypeFilter"]">
            <option value="@ViewData["FuelTypeFilter"]">Alle</option>
            @foreach (var item in Model.AllItems.OrderBy(s => s.fueltype).Select(s => s.fueltype).Distinct())
            {
                <option value=@item>@item</option>
            }
        </select>
        &nbsp;&nbsp;
        <b>Transmissie:</b>
        <select name="transmission" value="@ViewData["TransmissionFilter"]">
            <option value="@ViewData["TransmissionFilter"]">Alle</option>
            @foreach (var item in Model.AllItems.OrderBy(s => s.transmission).Select(s => s.transmission).Distinct())
            {
                <option value=@item>@item</option>
            }
        </select>
        &nbsp;&nbsp;
        <b>Kilometerstand: (vanaf)</b>
        <input name="milage" value="@ViewData["MilageFilter"]" type="text" onkeypress='return event.charCode >= 48 && event.charCode <= 57'><br /><br />
</div>
</form>







<br />
@await Html.PartialAsync("PaginationView")
<br />
<table class="table">
    <thead>
        <tr>
            <th>
                Merk
            </th>
            <th>
                Model
            </th>
            <th>
                Bouwjaar
            </th>
            <th>
                Kleur
            </th>
            <th>
                Prijs
            </th>
            <th>
                Brandstoftype
            </th>
            <th>
                Transmissie
            </th>
            <th>
                Kilometerstand
            </th>

            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.brand)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.model)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.manufactureyear)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.color)
                </td>
                <td>
                    €@Html.DisplayFor(modelItem => item.price)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.fueltype)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.transmission)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.mileage) km
                </td>
                <td>
                    <a asp-action="Edit" asp-route-id="@item.carid">Aanpassen</a> |
                    <a asp-action="Details" asp-route-id="@item.carid">Details</a> |
                    <a asp-action="Delete" asp-route-id="@item.carid">Verwijderen</a>
                </td>
            </tr>
        }
    </tbody>
</table>


@*<form asp-action="Index" method="get">
        <div class="form-actions no-color">
            <p>
                Huidig Filter(s):
                @ViewData["CurrentFilter"]
                @ViewData["ColorFilter"]
                @ViewData["FuelTypeFilter"]
                @ViewData["MotorTypeFilter"]
                @ViewData["TransmissionFilter"]
                <br>
                <br>

                Find by name: <input type="text" name="SearchString" value="@ViewData["currentFilter"]" />

                <select name="carColor" value="@ViewData["ColorFilter"]">
                    <option value="">Kleuren</option>
                    @foreach (var item in Model.Select(s => s.color).Distinct())
                    {
                        <option value=@item>@item</option>
                    }
                </select>
                <select name="FuelType" value="@ViewData["FuelTypeFilter"]">
                    <option value="">Brandstof</option>
                    @foreach (var item in Model.Select(s => s.fueltype).Distinct())
                    {
                        <option value=@item>@item</option>
                    }
                </select>
                <select name="motortype" value="@ViewData["MotorTypeFilter"]">
                    <option value="">Type motor</option>
                    @foreach (var item in Model.Select(s => s.enginetype).Distinct())
                    {
                        <option value=@item>@item</option>
                    }
                </select>

                <select name="transmission" value="@ViewData["TransmissionFilter"]">
                    <option value="">Transmissie</option>
                    @foreach (var item in Model.Select(s => s.transmission).Distinct())
                    {
                        <option value=@item>@item</option>
                    }
                </select>

                @*<b>Kilometerstand: (vanaf)</b>
                    <input type="number" onkeypress='return event.charCode >= 48 && event.charCode <= 57' name="SearchString" value="@ViewData["PrijsFilter"]" >

                <input type="submit" value="Zoeken" class="btn btn-default" /> |


                <a asp-action="Index">Verwijder Filter(s)</a>
            </p>
        </div>
    </form>*@